home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / share / tix4.1 / SGrid.tcl < prev    next >
Encoding:
Text File  |  1998-12-04  |  5.4 KB  |  229 lines

  1. # SGrid.tcl --
  2. #
  3. #    This file implements Scrolled Grid widgets
  4. #
  5. # Copyright (c) 1996, Expert Interface Technologies
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10.  
  11. tixWidgetClass tixScrolledGrid {
  12.     -classname TixScrolledGrid
  13.     -superclass tixScrolledWidget
  14.     -method {
  15.     }
  16.     -flag {
  17.     }
  18.     -configspec {
  19.     }
  20.     -default {
  21.     {.scrollbar            auto}
  22.     {*grid.borderWidth        1}
  23.     {*grid.Background        #c3c3c3}
  24.     {*grid.highlightBackground    #d9d9d9}
  25.     {*grid.relief            sunken}
  26.     {*grid.takeFocus        1}
  27.     {*Scrollbar.background        #d9d9d9}
  28.     {*Scrollbar.troughColor        #c3c3c3}
  29.     {*Scrollbar.takeFocus        0}
  30.     {*Scrollbar.relief        sunken}
  31.     {*Scrollbar.width        15}
  32.     }
  33. }
  34.  
  35. proc tixScrolledGrid:ConstructWidget {w} {
  36.     upvar #0 $w data
  37.  
  38.     tixChainMethod $w ConstructWidget
  39.  
  40.     set data(w:grid) [tixGrid $w.grid]
  41.  
  42.     set data(w:hsb) \
  43.     [scrollbar $w.hsb -orient horizontal -takefocus 0]
  44.     set data(w:vsb) \
  45.     [scrollbar $w.vsb -orient vertical -takefocus 0]
  46.  
  47.     set data(pw:client) $data(w:grid)
  48.  
  49.     pack $data(w:grid) -expand yes -fill both -padx 0 -pady 0
  50. }
  51.  
  52. proc tixScrolledGrid:SetBindings {w} {
  53.     upvar #0 $w data
  54.  
  55.     tixChainMethod $w SetBindings
  56.  
  57.     $data(w:grid) config \
  58.     -xscrollcommand "$data(w:hsb) set"\
  59.     -yscrollcommand "$data(w:vsb) set"\
  60.     -sizecmd "tixScrolledWidget:Configure $w" \
  61.     -formatcmd "tixCallMethod $w FormatCmd"
  62.  
  63.     $data(w:hsb) config -command "$data(w:grid) xview"
  64.     $data(w:vsb) config -command "$data(w:grid) yview"
  65.  
  66.     bindtags $data(w:grid) \
  67.     "$data(w:grid) TixSGrid TixGrid [winfo toplevel $data(w:grid)] all"    
  68.  
  69.     tixSetMegaWidget $data(w:grid) $w
  70. }
  71.  
  72. #----------------------------------------------------------------------
  73. #            RAW event bindings
  74. #----------------------------------------------------------------------
  75. proc tixScrolledGridBind {} {
  76.     tixBind TixScrolledGrid <ButtonPress-1> {
  77.     tixScrolledGrid:Button-1 [tixGetMegaWidget %W] %x %y
  78.     }
  79.     tixBind TixScrolledGrid <Shift-ButtonPress-1> {
  80.     tixScrolledGrid:Shift-Button-1 %W %x %y
  81.     }
  82.     tixBind TixScrolledGrid <Control-ButtonPress-1> {
  83.     tixScrolledGrid:Control-Button-1 %W %x %y
  84.     }
  85.     tixBind TixScrolledGrid <ButtonRelease-1> {
  86.     tixScrolledGrid:ButtonRelease-1 %W %x %y
  87.     }
  88.     tixBind TixScrolledGrid <Double-ButtonPress-1> {
  89.     tixScrolledGrid:Double-1 %W  %x %y
  90.     }
  91.     tixBind TixScrolledGrid <B1-Motion> {
  92.     set tkPriv(x) %x 
  93.     set tkPriv(y) %y
  94.     set tkPriv(X) %X
  95.     set tkPriv(Y) %Y
  96.  
  97.     tixScrolledGrid:B1-Motion %W %x %y
  98.     }
  99.     tixBind TixScrolledGrid <Control-B1-Motion> {
  100.     set tkPriv(x) %x 
  101.     set tkPriv(y) %y
  102.     set tkPriv(X) %X
  103.     set tkPriv(Y) %Y
  104.  
  105.     tixScrolledGrid:Control-B1-Motion %W %x %y
  106.     }
  107.     tixBind TixScrolledGrid <B1-Leave> {
  108.     set tkPriv(x) %x 
  109.     set tkPriv(y) %y
  110.     set tkPriv(X) %X
  111.     set tkPriv(Y) %Y
  112.  
  113.     tixScrolledGrid:B1-Leave %W
  114.     }
  115.     tixBind TixScrolledGrid <B1-Enter> {
  116.     tixScrolledGrid:B1-Enter %W %x %y
  117.     }
  118.     tixBind TixScrolledGrid <Control-B1-Leave> {
  119.     set tkPriv(x) %x 
  120.     set tkPriv(y) %y
  121.     set tkPriv(X) %X
  122.     set tkPriv(Y) %Y
  123.  
  124.     tixScrolledGrid:Control-B1-Leave %W
  125.     }
  126.     tixBind TixScrolledGrid <Control-B1-Enter> {
  127.     tixScrolledGrid:Control-B1-Enter %W %x %y
  128.     }
  129.  
  130.     # Keyboard bindings
  131.     #
  132.     tixBind TixScrolledGrid <Up> {
  133.     tixScrolledGrid:DirKey %W up
  134.     }
  135.     tixBind TixScrolledGrid <Down> {
  136.     tixScrolledGrid:DirKey %W down
  137.     }
  138.     tixBind TixScrolledGrid <Left> {
  139.     tixScrolledGrid:DirKey %W left
  140.     }
  141.     tixBind TixScrolledGrid <Right> {
  142.     tixScrolledGrid:DirKey %W right
  143.     }
  144.     tixBind TixScrolledGrid <Prior> {
  145.     %W yview scroll -1 pages
  146.     }
  147.     tixBind TixScrolledGrid <Next> {
  148.     %W yview scroll 1 pages
  149.     }
  150.     tixBind TixScrolledGrid <Return> {
  151.     tixScrolledGrid:Return %W 
  152.     }
  153.     tixBind TixScrolledGrid <space> {
  154.     tixScrolledGrid:Space %W 
  155.     }
  156. }
  157.  
  158. #----------------------------------------------------------------------
  159. #
  160. #
  161. #             Mouse bindings
  162. #
  163. #
  164. #----------------------------------------------------------------------
  165. proc tixScrolledGrid:Button-1 {w x y} {
  166.     if {[$w cget -state] == "disabled"} {
  167.     return
  168.     }
  169.     if [$w cget -takefocus] {
  170.     focus $w
  171.     }
  172.     case [tixScrolled:GetState $w] {
  173.     {0} {
  174.         tixScrolledGrid:GoState s1 $w $x $y
  175.            }
  176.     {b0} {
  177.         tixScrolledGrid:GoState b1 $w $x $y
  178.            }
  179.     {m0} {
  180.         tixScrolledGrid:GoState m1 $w $x $y
  181.            }
  182.     {e0} {
  183.         tixScrolledGrid:GoState e1 $w $x $y
  184.            }
  185.     }
  186. }
  187.  
  188.  
  189.  
  190. #----------------------------------------------------------------------
  191. #
  192. #        option configs
  193. #----------------------------------------------------------------------
  194.  
  195. #----------------------------------------------------------------------
  196. #
  197. #        Widget commands
  198. #----------------------------------------------------------------------
  199.  
  200.  
  201. #----------------------------------------------------------------------
  202. #
  203. #        Private Methods
  204. #----------------------------------------------------------------------
  205.  
  206. #----------------------------------------------------------------------
  207. #        Virtual Methods
  208. #----------------------------------------------------------------------
  209. proc tixScrolledGrid:FormatCmd {w area x1 y1 x2 y2} {
  210.     # do nothing
  211. }
  212.  
  213. #----------------------------------------------------------------------
  214. # virtual functions to query the client window's scroll requirement
  215. #----------------------------------------------------------------------
  216. proc tixScrolledGrid:GeometryInfo {w mW mH} {
  217.     upvar #0 $w data
  218.  
  219.  
  220.     if {$mW < 1} {
  221.     set mW 1
  222.     }
  223.     if {$mH < 1} {
  224.     set mH 1
  225.     }
  226.  
  227.     return [$data(w:grid) geometryinfo $mW $mH]
  228. }
  229.